package cn.com.blueInfo.bpm.number.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.number.request.NumberRuleDTO;
import cn.com.blueInfo.bpm.number.response.NumberRuleVO;
import cn.com.blueInfo.bpm.number.service.NumberRuleService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 编号规则定义表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:05
 */
@Tag(name = "编号规则定义 接口")
@RestController
@RequestMapping("/number/numberRule")
public class NumberRuleController extends BaseController {

    @Autowired
    private NumberRuleService numberRuleService;

    /**
     * 新建编号规则定义
     * @param numberRuleDTO 编号规则定义参数
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则定义")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createNumberRule(
            @Validated({Create.class, Default.class}) @RequestBody NumberRuleDTO numberRuleDTO) {
        return numberRuleService.addNumberRule(numberRuleDTO);
    }

    /**
     * 批量新建编号规则定义
     * @param numberRuleDTOList 编号规则定义参数列表
     * @return ResultInfo
     */
    @Operation(summary = "新增编号规则定义")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreateNumberRule(
            @Validated({Create.class, Default.class}) @RequestBody List<NumberRuleDTO> numberRuleDTOList) {
        return numberRuleService.batchAddNumberRule(numberRuleDTOList);
    }

    /**
     * 根据ID删除编号规则定义
     * @param numberRuleId 编号规则定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则定义")
    @DeleteMapping("/removeInfo/{numberRuleId}")
    public ResultInfo<Integer> deleteNumberRuleById(
            @Parameter(name = "ID") @PathVariable Long numberRuleId) {
        return numberRuleService.removeNumberRule(numberRuleId);
    }

    /**
     * 批量根据ID删除编号规则定义
     * @param numberRuleIdList 编号规则定义ID列表
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除编号规则定义")
    @DeleteMapping("/removeInfoList/{numberRuleIdList}")
    public ResultInfo<Integer> deleteNumberRuleById(
            @Parameter(name = "ID") @PathVariable List<Long> numberRuleIdList) {
        return numberRuleService.batchRemoveNumberRule(numberRuleIdList);
    }

    /**
     * 根据ID全量更新编号规则定义
     * @param numberRuleId  编号规则定义ID
     * @param numberRuleDTO 编号规则定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新编号规则定义")
    @PutMapping("/modifyInfo/{numberRuleId}")
    public ResultInfo<Integer> updateNumberRuleFull(
            @Parameter(name = "ID") @PathVariable Long numberRuleId,
            @Validated({Update.class, Default.class}) @RequestBody NumberRuleDTO numberRuleDTO) {
        validateUpdateId(numberRuleId, numberRuleDTO.getId());
        return numberRuleService.modifyNumberRule(numberRuleDTO);
    }

    /**
     * 根据ID部分更新编号规则定义
     * @param numberRuleId               编号规则定义ID
     * @param numberRuleUpdatePartialDTO 编号规则定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新编号规则定义")
    @PatchMapping("/modifyPartialInfo/{numberRuleId}")
    public ResultInfo<Integer> updateNumberRulePartial(
            @Parameter(name = "ID") @PathVariable Long numberRuleId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            NumberRuleDTO.UpdatePartialDTO numberRuleUpdatePartialDTO) {
        validateUpdateId(numberRuleId, numberRuleUpdatePartialDTO.getId());
        return numberRuleService.modifyNumberRulePartial(numberRuleUpdatePartialDTO);
    }

    /**
     * 根据ID查询编号规则定义
     * @param numberRuleId 编号规则定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询编号规则定义")
    @GetMapping("/getInfo/{numberRuleId}")
    public ResultInfo<NumberRuleVO> getNumberRuleById(
            @Parameter(name = "ID") @PathVariable Long numberRuleId) {
        return numberRuleService.queryNumberRuleById(numberRuleId);
    }

    /**
     * 分页查询编号规则定义
     * @param numberRuleQueryDTO 编号规则定义参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询编号规则定义")
    @GetMapping("/getInfos")
    public ResultInfo<Page<NumberRuleVO>> getNumberRulePage(
            @Validated NumberRuleDTO.QueryDTO numberRuleQueryDTO) {
        return numberRuleService.queryNumberRulePage(numberRuleQueryDTO);
    }

    /**
     * 根据条件查询编号规则定义
     * @param numberRuleQueryDTO 编号规则定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询编号规则定义")
    @GetMapping("/getInfoList")
    public ResultInfo<List<NumberRuleVO>> getNumberRuleList(
            @Validated NumberRuleDTO.QueryDTO numberRuleQueryDTO) {
        return numberRuleService.queryNumberRuleList(numberRuleQueryDTO);
    }

}
